package com.charging.business.vo;

import com.alibaba.fastjson2.annotation.JSONField;
import com.charging.business.jin.EnStations;
import com.charging.business.vo.obj.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author JerryLu
 * @date 2024/9/26 15:43
 * @description 出口计费响应参数
 */
@EqualsAndHashCode(callSuper = false)
@Data
public class FeeExCalcResponse {

    /**
     * 通知消息号
     * 收到的请求消息号
     * 必填：是
     */
    @JSONField(ordinal = 0)
    public String msgId = "";

    /**
     * 响应码
     * 必填：是
     * 0-成功
     * 非0-失败
     */
    @JSONField(ordinal = 1)
    public Integer code = 0;

    /**
     * 响应描述信息
     * 必填：否
     */
    @JSONField(ordinal = 2)
    public String codeInfo = "";

    /**
     * 接收时间
     * yyyy-MM-dd'T'HH:mm:ss
     * 必填：是
     */
    @JSONField(ordinal = 3)
    public String receiveTime;

    /**
     * 计费方式
     * 必填：是
     * 1-按OBU内累计优惠后金额计费
     * 2-按OBU内累计优惠前金额计费(废弃)
     * 3-按CPC卡内累计金额计费
     * 4-省中心在线服务计费
     * 5-部中心在线服务计费
     * 6-按全网可达最短路径计费
     * 11-开放式计费
     */
    @JSONField(ordinal = 4)
    public Integer exitFeeType = 0;

    /**
     * OBU计费结果
     * 必填：否, 计费方式1必填，见下etcFeeInfo说明
     */
    @JSONField(ordinal = 5)
    public EtcFeeInfo etcFeeInfo = null;

    /**
     * CPC计费结果
     * 必填：否, 计费方式3必填，见下cpcFeeInfo说明
     */
    @JSONField(ordinal = 6)
    public CpcFeeInfo cpcFeeInfo = null;

    /**
     * 在线计费结果
     * 必填：否,计费方式4、5必填，见下onlineFeeInfo说明
     */
    @JSONField(ordinal = 7)
    public OnlineFeeInfo onlineFeeInfo = null;

    /**
     * 最小费额计费结果
     * 必填：计费成功必填
     */
    @JSONField(ordinal = 8)
    public MiniFeeInfo miniFeeInfo = null;

    /**
     * 开放式计费结果
     * 必填：否, 计费方式11必填，见下openFeeInfo说明
     */
    @JSONField(ordinal = 9)
    public Object openFeeInfo = null;

    /**
     * 差异化优惠状态
     * 必填：是
     * 0-非差异化优惠
     * 1-差异化优惠
     */
    @JSONField(ordinal = 10)
    public Integer diffState = 0;

    /**
     * 差异化优惠应收总金额
     * 必填：diffState为1时必填
     */
    @JSONField(ordinal = 11)
    public Integer diffTotalPayFee = null;

    /**
     * 差异化优惠实收总金额
     * 必填：diffState为1时必填
     */
    @JSONField(ordinal = 12)
    public Integer diffTotalRealFee = null;

    /**
     * 差异化优惠信息
     * 必填：diffState为1时必填
     */
    @JSONField(ordinal = 13)
    public String diffInfo = null;

    /**
     * 差异化优惠明细
     * 必填：diffState为1时必填
     */
    @JSONField(ordinal = 14)
    public List<DiffFeeInfo> diffFeeInfo = null;

    /**
     * 计费模块和计费参数版本号
     * 不超过 40 个字符。 计费模块版本号与计费参数版本号使用“|” 分隔
     * 必填：是
     */
    @JSONField(ordinal = 15)
    public String rateVersion = "";

    /**
     * 最小费额费率版本号
     * 不超过 40 个字符
     * 必填：是
     */
    @JSONField(ordinal = 16)
    public String spcRateVersion = "";

    /**
     * 计费耗时(ms)
     * 必填：是
     */
    @JSONField(ordinal = 17)
    public Integer calCostTime = 0;

    /**
     * 特情类型
     * 计费服务判断的特情， 参见编码规则。 多种特情时， 以“|”分隔,若多个以“|”分割
     * 必填：否
     * 0 - 正常
     * 1 - OBU 未发行
     * 2 - OBU 不可读
     * 3 - OBU 拆卸
     * 4 - 入出口车牌不一致
     * 5 - 入出口车型不一致
     * 6 - 入出口车种不一致
     * 7 - 无入口信息
     * 8 - 无卡
     * 9 - 坏卡
     * 10 - 纸质通行券处理
     * 11 - 补交处理
     * 12 - CPC卡灰名单
     * 13 - OBU黑名单
     * 14 - 信用黑名
     * 15 - 信用灰名单
     */
    @JSONField(ordinal = 18)
    public String specialType = "";

    /**
     * 补充入站信息
     */
    @JSONField(ordinal = 19)
    public List<EnStations> enStationInfo = new ArrayList<>();

    /**
     * 省中心计费请求接收时间
     */
    @JSONField(ordinal = 20)
    public String proRequestTime = "";

    /**
     * 省中心计费响应发出时间
     */
    @JSONField(ordinal = 21)
    public String proResponseTime = "";

    /**
     * 部中心计费请求时间
     */
    @JSONField(ordinal = 22)
    public String minRequestTime = "";

    /**
     * 部中心计费响应时间
     */
    @JSONField(ordinal = 23)
    public String minResponseTime = "";

    /**
     * 获取总应收金额
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int sumPayFee() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.payFee;
        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.payFee;
        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.payFee;
        } else if (exitFeeType == 6) {// 兜底
            res = miniFeeInfo.calMinFeeFee; // todo
        }
        return res;
    }

    /**
     * 获取总实收金额
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int sumFee() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.fee;
        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.fee;
        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.splitAmount;
        } else if (exitFeeType == 6) {// 兜底
            int a = 0;
            for (SplitProvinceMini prov : miniFeeInfo.splitProvince) {
                a += prov.calMinFeeFee;
            }
            res = a;
        }
        return res;
    }

    /**
     * 获取总优惠金额
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int sumDiscountFee() {
        int res = sumPayFee() - sumFee();
        return res;
    }

    /**
     * 获取总里程
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int sumFeeMileage() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.feeMileage;
        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.feeMileage;
        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.feeMileage;
        } else if (exitFeeType == 6) {// 兜底
            res = miniFeeInfo.calMinFeeMileage;
        }
        return res;
    }

    /**
     * 获取本省应收金额
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int payFeeProvSumLocal() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.feeInfo.feeSpare1;

        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.payFeeProvSumLocal();

        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.payFeeProvSumLocal();
        } else if (exitFeeType == 6) {// 兜底
            res = miniFeeInfo.payFeeProvSumLocal();
        }
        return res;
    }

    /**
     * 获取本省实收金额
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int feeProvSumLocal() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.feeInfo.feeProvSumLocal;

        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.feeProvSumLocal();

        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.feeProvSumLocal();
        } else if (exitFeeType == 6) {// 兜底
            res = miniFeeInfo.feeProvSumLocal();
        }
        return res;
    }

    /**
     * 获取本省里程
     *
     * @return
     */
    @JSONField(serialize = false, deserialize = false)
    public int feeMileageProvSumLocal() {
        int res = 0;
        if (exitFeeType == 1) {// OBU内信息
            res = etcFeeInfo.feeInfo.feeSpare2;
        } else if (exitFeeType == 3) {// CPC内信息
            res = cpcFeeInfo.feeMileageProvSumLocal();
        } else if (exitFeeType == 4 || exitFeeType == 5) {// 在线计费
            res = onlineFeeInfo.feeMileageProvSumLocal();
        } else if (exitFeeType == 6) {// 兜底
            res = miniFeeInfo.feeMileageProvSumLocal();
        }
        return res;
    }

    @JSONField(serialize = false, deserialize = false)
    public int NhPayFee() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.payFee;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.payFee;
        }
        return 0;
    }

    @JSONField(serialize = false, deserialize = false)
    public int NhFee() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.realFee;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.realFee;
        }
        return 0;
    }

    @JSONField(serialize = false, deserialize = false)
    public int NhDiscountFee() {
        return NhPayFee() - NhFee();
    }

    @JSONField(serialize = false, deserialize = false)
    public String payFeeGroup() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.payFeeGroup;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.payFeeGroup;
        }
        return "";
    }

    @JSONField(serialize = false, deserialize = false)
    public String discountFeeGroup() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.discountFeeGroup;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.discountFeeGroup;
        }
        return "";
    }

    @JSONField(serialize = false, deserialize = false)
    public String feeGroup() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.feeGroup;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.feeGroup;
        }
        return "";
    }

    @JSONField(serialize = false, deserialize = false)
    public String tollIntervalIDs() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.tollIntervalIDs;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.tollIntervalIDs;
        }
        return "";
    }

    @JSONField(serialize = false, deserialize = false)
    public String feeInfo1() {
        if (exitFeeType == 1) {
            return etcFeeInfo.feeInfo.feeInfo1;
        } else if (exitFeeType == 3) {
            return cpcFeeInfo.feeInfo.feeInfo1;
        }
        return "";
    }
}
